package com.kzd.gtgame.main.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.view.animation.TranslateAnimation
import android.widget.*
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.TimeUtils
import com.kzd.gtgame.R
import com.kzd.gtgame.custom.setOnClickAntiShakeListener
import com.kzd.gtgame.db.GameDownload
import com.kzd.gtgame.entity.WelfareCoupon
import com.kzd.gtgame.main.home.adapter.CouponPriceAdapter
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AlphaConfig
import razerdp.util.animation.AnimationHelper
import java.lang.Exception
import java.lang.StringBuilder


class DownloadDeletePopup(
    context: Context, val onClick: (view: View, gameDownload: GameDownload) -> Unit
) : BasePopupWindow(context) {

    private var gameDownload: GameDownload? = null

    init {
        popupGravity = Gravity.CENTER
        setOverlayNavigationBar(false)
    }

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_download_delete)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        contentView.findViewById<TextView>(R.id.tvDownloadDeleteCancel).setOnClickAntiShakeListener {
            dismiss()
        }
        contentView.findViewById<TextView>(R.id.tvDownloadDeleteConfirm).setOnClickAntiShakeListener {
            dismiss()
            gameDownload?.let { download ->
                onClick(it, download)
            }
        }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.IN)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.OUT)
            .toDismiss()
    }

    fun setData(gameDownload: GameDownload): DownloadDeletePopup {
        this.gameDownload = gameDownload
        return this
    }

}